package com.itstyle.quartz.web;

import com.itstyle.quartz.entity.DetailsBean;
import com.itstyle.quartz.entity.Result;
import com.itstyle.quartz.entity.Userinfo;
import com.itstyle.quartz.service.IDetailsBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/details")

public class DetailsController {

    @Autowired
    private IDetailsBeanService detailsBeanService;

    @PostMapping("/list")
    public Result list(DetailsBean detailsBean, Integer pageNo, Integer pageSize) {
        return detailsBeanService.listDetailsBean(detailsBean, pageNo, pageSize);
    }

    @PostMapping("/add")
    public Result save(DetailsBean detailsBean) {
        try {
            detailsBeanService.save(detailsBean);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error();
        }
        return Result.ok();
    }

    @PostMapping("/update")
    public Result update(DetailsBean detailsBean) {
        try {
            detailsBeanService.update(detailsBean);
        } catch (Exception e) {
            e.printStackTrace();
            Result.error();
        }
        return Result.ok();
    }

    @PostMapping("/remove")
    public Result remove(DetailsBean detailsBean) {
        try {
            detailsBeanService.delete(detailsBean);
        } catch (Exception e) {
            e.printStackTrace();
            Result.error();
        }
        return Result.ok();
    }

}
